<?php
if ($_SESSION['login_user']['status'] != 'admin' || LZ_MODULE != 'admin') die('Access Denied');

$m = $_GET['m'];
include_once('model/guestbook.php');
$obj = new LZ_Guestbook;

if ($m == 'new')
{
	$data = filter_array($_POST,'name!,email,content!');
	if ($data)
	{
		$data['date'] = time();
		echo ($obj->add($data))?'success':'error';
	}
	else 
		echo FILL_ALL;
	die;	
}

$total = $obj->get_list( array('select' => 'count(*)') );
$total = $total[0]['count(*)'];
$page = intval($_GET['page']);
$per_page = (intval($config['guestbook_per_page']))?intval($config['guestbook_per_page']):30;
!$page && $page=1;
$total_page = ceil($total/$per_page);
!$total_page && $total_page=1;
$page>$total_page && $page = $total_page;
$gb_list = $obj->get_list( array('from' => ($page-1)*$per_page,'total'=>$per_page,'asc'=>false));

$pager = PAGER_TOTAL.$total.PAGER_ITEMS.$total_page.PAGER_PAGE.'<br />';
$pager.= html_pager("admin.php?p=guestbook",$total_page,$page);

$view_data['pager'] = $pager;

$view_data['items'] = $gb_list;
$view_data['page_description'] = GUESTBOOK;
$view_data['title'] = GUESTBOOK;

?>